package com.app.dao.service.impl;

import com.app.dao.entity.Record;
import com.app.dao.mapper.RecordMapper;
import com.app.dao.service.RecordService;
import com.app.model.dto.PageDTO;
import com.app.utils.UserContext;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 记录表 服务实现类
 * </p>
 *
 * @author admin
 * @since 2023
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements RecordService {
    @Override
    public Page<Record> page(PageDTO pageDTO) {
        return lambdaQuery()
                .eq(Record::getCreateBy, UserContext.getUser().getUsername())
                .orderByDesc(Record::getCreateTime).page(pageDTO.getMybatisPage());
    }

    @Override
    public List<Record> listAll() {
        return lambdaQuery()
                .eq(Record::getCreateBy, UserContext.getUser().getUsername())
                .list();
    }

    @Override
    public Record getRecordById(String id) {
        return getById(id);
    }

    @Override
    public boolean deleteRecordById(String id) {
        return removeById(id);
    }

    @Override
    public boolean addRecord(Record obj) {
        return save(obj);
    }

    @Override
    public boolean updateRecordById(Record obj) {
        return updateById(obj);
    }
}
